package com.yueke.gemini.service.impl;

import com.yueke.gemini.context.TenantContextHolder;
import com.yueke.gemini.model.User;
import com.yueke.gemini.repository.UserRepository;
import com.yueke.gemini.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * created by admin 2020/3/7 19:18
 */
@Service("userService")
public class UserServiceImpl implements UserService {


    @Autowired
    private UserRepository userRepository;

//    private static TwitterIdentifier identifier = new TwitterIdentifier();



    @Override
    public void save(User user) {
//        user.setId(identifier.generalIdentifier());
//        user.setTenant(TenantContextHolder.getTenant());
        userRepository.save(user);
    }

    @Override
    public User findById(String userId) {
//        Optional<User> optional = userRepository.findById(userId);
//        if(optional.isPresent()){
//            return optional.get();
//        }else{
//            return null;
//        }

        return null;
    }

    @Override
    public User findByUsername(String username) {
        System.out.println(TenantContextHolder.getTenant());
        return userRepository.findByUsername(username);
    }
}
